<?php

namespace App\Http\Controllers\Api\V1\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class UserTeamResource extends JsonResource
{
    public function toArray($request)
    {
	    $resource = $this->resource;

        $data = [
	        'id' => (int)$resource->id,
		    'parent_id' => (int)$resource->parent_id,
		    'is_valid_vip'=> !empty($resource->isValidVip()) ?  '1' :  '0',

	        'grade' => (string)$resource->grade,
		    'invite_code' => (string)$resource->invite_code,
	        //'invite_string' => $resource->inviteString(),

	        'name' => $resource->name ?? '',
	        'nickname' => $resource->nickname ?? '',
	        'phone' => $resource->contact_phone ?? '',
	        'signature' => $resource->signature ?? '',
	        'avatar_url' => img_path($resource->avatar),
	        'gender' => $resource->gender ?? '',
	        'birthday' => $resource->birthday ?? '',

	        'dividend_all' => $resource->dividend_all,
	        'dividend_day' => $resource->dividend_day,

            'has_gold_support' => $resource->hasGoldSupport(),

	        'is_pay_code_set' => $resource->isPayCodeSet(),

	        'is_phone_bound' => $resource->isPhoneBound(),
	        'is_weixin_bound' => $resource->isWeixinBound(),
	        'is_weimini_bound' => $resource->isWeiminiBound(),
	        'is_alipay_bound' => $resource->isAlipayBound(),

	        'wx_nickname' => $resource->wx_nickname ?? '',
	        'wx_headimgurl' => $resource->wx_headimgurl ?? '',
	        'alipay_nickname' => $resource->alipay_nickname ?? '',
	        'alipay_avatar' => $resource->alipay_avatar ?? '',
	        'alipay_user_no' => $resource->alipay_user_no ?? '',

	        'parent_phone' => $resource->parent_phone,
	        'parent_name' => $resource->parent_name,
	        'parent_avatar_url' => img_path($resource->parent_avatar),

	        'dividend_parent_rate' => $resource->dividendApplesRate(),
	        'team_number' => $resource->team_number,
	        'created_at' => (string)$resource->created_at,
	        'wechat_account' => $resource->wechat_account,
	        'qq_account' => $resource->qq_account,
	        'contact_phone' => $resource->contact_phone ?? '',
	        'user_level' =>$resource->user_level,
			'team_level' => $resource->team_level, 
			'order_num' => $resource->order_num, 
			'dividend_parent_rewards' => $resource->dividendParentRewards(), 
			'dividend_parent_apples' => $resource->dividendParentApples(), 
			'one_day_parent_apples' => $resource->oneDayParentApples(),
        ];

        return $data;
    }
}
